/**
 * 贷后管理跟踪日志
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class noteCtrl {
  constructor($scope,$rootScope,http,$ui) {
  	  console.log($scope.params)
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
  	  $scope.param1={
  	  	oid:JSON.parse($scope.params).id,
  	  	send_type:JSON.parse($scope.params).logs_type
  	  }
  	  //日志信息
  	  $scope.xinXi=function(){
  	  		http.post('sendMessageSelect.do',$scope.param1,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'.note'
					})
					$scope.page=data.data
					$scope.param2=data.data.list
					$scope.$apply()
					if($scope.param2.length<1){
						//没有短信记录跳到短信发送弹窗
						$scope.addnote()
					}
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.note'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  	  $scope.xinXi()
  	  //添加日志跳转方法
  	  $scope.operation = function (path,item) {
		console.log('111')
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1],{id:1,ids:2})
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+" params="+params+"></"+_path[1]+">"})
        }
   	  }
  	  //添加日志
  	  $scope.addnote=function(){
  	  	$scope.cancel();//关闭日志记录弹窗
  	  	console.log('添加日志')
  	  	$scope.param_s={
	  	  	id:JSON.parse($scope.params).id,
	  	  	logs_type:JSON.parse($scope.params).logs_type,
	  	  	phone:JSON.parse($scope.params).phone,
	  	  	recive_name:JSON.parse($scope.params).recive_name,
	  	  	pid:JSON.parse($scope.params).pid
	  	  }
  	  	$scope.operation('alert@addnote',$scope.param_s)//弹出添加日志弹窗
  	  }
  }
}
noteCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.note', []).directive('note', function() {
    return {
        template: tem,
        replace:true,
        controller: noteCtrl,
        scope:{
        	params:"@"
        }
    }
}).name